/*
 * Copyright (C) 2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

/*
 * Prototypes
 */
#if PROTO
static void
vo_den_vo(vo_t *u, vo_t *v, eint32_t m);
#endif

/*
 * Implementation
 */
#if CODE
void
evector_den(evector_t *v, etype_t t)
{
    eint32_t	 l;
    evector_t	*r;
    v_enter();

    v_check(1);
    l = v->length;
    switch (t) {
	case t_int8:	case t_uint8:
	case t_int16:	case t_uint16:
	case t_int32:	case t_uint32:
	case t_int64:	case t_uint64:
	    /* integers are rationals with denominator == 1 */
	    r = create(v, t_int8);
	    memset(r->v.obj, 1, l);
	    v_leave();
	    return;
	case t_void:
	    break;
	default:
	    eraise_exception(except_not_a_rational_number);
    }

    r = create(v, t_void);
    vo_den_vo(r->v.obj, v->v.obj, l);
    v_leave();
}

static void
vo_den_vo(vo_t *u, vo_t *v, eint32_t m)
{
    for (; m; u++, v++, m--) {
	switch (eobject_type(*v)) {
	    case t_void:
	    case t_int:
	    case t_mpz:
		set_i(1);
		break;
	    case t_mpq:
		set_z_check(mpq_denref(get_q(v)));
		break;
	    default:
		eraise_exception(except_not_a_rational_number);
	}
    }
}
#endif
